package com.wmm.controller;

import com.wmm.domain.Employee;
import com.wmm.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;


@Controller
@RequestMapping("/employee")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;


    @RequestMapping("/list")
    public String findAll(Model model) {
        Employee employee = new Employee();
        List<Employee> list = employeeService.findAllWithId(employee);
        model.addAttribute("list",list);
        return "list";
    }

    @RequestMapping("/save")
    public String save(Employee employee) {
        System.out.println("11111");
        employeeService.addEmployee(employee);


        return "forward:/employee/list";
    }

    @RequestMapping("/find")
    public String find(Employee employee,Model model) {
        if("".equals(employee.getEmpId())) {
            employee.setDeptId(null);
        } else {
            model.addAttribute("deptId",employee.getEmpId());

        }

        List<Employee> list = employeeService.findAllWithId(employee);
        model.addAttribute("list",list);

        return "list";
    }
}
